package com.corpgovernment.organization.controller.budget;

import com.corpgovernment.api.organization.bo.budget.*;
import com.corpgovernment.organization.service.budget.OccupyBudgetService;
import com.corpgovernment.organization.service.budget.ReleaseBudgetService;
import com.corpgovernment.organization.service.budget.SearchBudgetService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@Slf4j
@RestController
@RequestMapping("/useBudget")
public class BudgetUseController {

	@Autowired
	private SearchBudgetService searchBudgetService;
	@Autowired
	private OccupyBudgetService occupyBudgetService;
	@Autowired
	private ReleaseBudgetService releaseBudgetService;

	/**
	 * 查询预算
	 */
	@RequestMapping(value = "/searchBudget", method = RequestMethod.POST)
	@ResponseBody
	public SearchBudgetResponseBO searchBudget(@RequestBody @Valid SearchBudgetRequestBO searchBudgetRequest, Errors errors) {
		return searchBudgetService.searchBudget(searchBudgetRequest);
	}

	/**
	 * 预占预算
	 */
	@RequestMapping(value = "/occupyBudget", method = RequestMethod.POST)
	@ResponseBody
	public OccupyBudgetResponseBO occupyBudget(@RequestBody @Valid OccupyBudgetRequestBO occupyBudgetRequest, Errors errors) {
		return occupyBudgetService.handleRequest(occupyBudgetRequest);
	}

	/**
	 * 释放预算
	 */
	@RequestMapping(value = "/releaseBudget", method = RequestMethod.POST)
	@ResponseBody
	public ReleaseBudgetResponseBO releaseBudget(@RequestBody @Valid ReleaseBudgetRequestBO releaseBudgetRequest, Errors errors) {
		return releaseBudgetService.handleRequest(releaseBudgetRequest);
	}
}